//    Copyright (C) Kherty.  All rights reserved.
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace OpenLS.Spreadsheet.UI
{
    /// <summary>
    /// Interaction logic for AlignmentControl.xaml
    /// </summary>
    /// 
    [Browsable(false)]
    public partial class AlignmentControl
    {
        public AlignmentControl()
        {
            Loaded += AlignmentControl_Loaded;
            InitializeComponent();
        }

        private void AlignmentControl_Loaded(object sender, RoutedEventArgs e)
        {
           //\\ var cellFormatter = (RangeFormatter) DataContext;
            AlignmentFormatter r = (AlignmentFormatter)DataContext;
            if (r == null)
                return;

            if (r.VerticalAlignment != null)
                verticalAlignmentControl.SelectedIndex = (int) r.VerticalAlignment;
            if (r.HorizontalAlignment != null)
                horizontalAlignmentControl.SelectedIndex = (int) r.HorizontalAlignment.Value;
        }

        private void OnHorizontalAlignmentChanged(object sender, SelectionChangedEventArgs e)
        {
            var a = (HorizontalCellAlignment) ((Selector) sender).SelectedIndex;
            AlignmentFormatter r = GetStyleRecord();
            r.HorizontalAlignment =  a;
        }

        private void OnVerticalAlignmentChanged(object sender, SelectionChangedEventArgs e)
        {
            var a = (VerticalCellAlignment) ((Selector) sender).SelectedIndex;
            AlignmentFormatter r = GetStyleRecord();
            r.VerticalAlignment = a;
        }

        private AlignmentFormatter GetStyleRecord()
        {
           //\\ RangeFormatter rangeFormatter = (RangeFormatter) DataContext;
            return (AlignmentFormatter)DataContext;
        }
    }
}